﻿@model MsForgeReboot.Framework.ViewModels.UserViewModel

<link href="@Styles.Url("~/Content/select2.css")" rel="stylesheet"/>

<span class="add-on"><i class="icon-user"></i></span>
<input type="text" name="@Html.NameFor(m => m.Id)" id="@Html.IdFor(m => m.Id)" />

<script src="@Scripts.Url("~/Scripts/select2-3.4.0/Select2.js")"></script>
<script src="@Scripts.Url("~/Scripts/select2-3.4.0/select2_locale_sr-Latn-RS.js")"></script>

<script>
   
    $(document).ready(function () {
   
        
        $('#@Html.IdFor(m => m.Id)').select2({
            placeholder: "Izaberite korisnički nalog",
            minimumInputLength: 2,
            ajax: {
                url: '@Url.Action("Search", "Account", new { Area = ""})',
                dataType: 'json',
                data: function (term, page) {
                    return {
                        term: term, // search term
                    };
                },
                results: function (data, page) {
                    // parse the results into the format expected by Select2.
                    return { results: data };
                }
            }            
        });
     @if (Model.Id != 0) {
         @:$('#@Html.IdFor(m => m.Id)').select2('data', { id: @Model.Id , text: '@Model.PublicName' });
     }
    });

</script>
